package com.xfp.controller;

import com.xfp.pojo.dto.VmDto;
import com.xfp.pojo.dto.VmPolicyListDto;
import com.xfp.pojo.dto.VmQueryDto;
import com.xfp.pojo.dto.newVmDto;
import com.xfp.pojo.entity.Policy;
import com.xfp.pojo.vo.VmPolicyVo;
import com.xfp.pojo.vo.VmQueryVO;
import com.xfp.pojo.vo.newVmVo;
import com.xfp.result.Result;
import com.xfp.service.VmService;
import com.xfp.service.VmTypeSrevice;
import com.xfp.service.impl.VmServiceImp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service")
@Api(tags = "售货机管理")
@Slf4j
public class VmController {

    @Autowired
    private VmService vm;

    /**
     * 售货机搜索
     */
    @GetMapping("/vm/search")
    @ApiOperation("售货机分页查询")
    public VmQueryVO pageVm(VmQueryDto dto){
        log.info("售货机分页查询:{}",dto);
        VmQueryVO vo = vm.pageVm(dto);
        return vo;
    }

    /**
     * 新增售货机
     */
    @PostMapping("/vm")
    @ApiOperation("新增售货机")
    public newVmVo insertVm(@RequestBody newVmDto dto){
        log.info("新增售货机,{]",dto);
        newVmVo vo = vm.insertVm(dto);
        System.out.println(vo);
        return vo;
    }

    /**
     * 售货机——修改
     */
    @PutMapping("/vm/{id}/{nodeId}")
    @ApiOperation("修改售货机点位")
    public Boolean updateVm(@PathVariable String id,@PathVariable String nodeId){
        log.info("修改售货机：{},{}",id,nodeId);
        vm.updateVm(id,nodeId);
        return true;
    }

    /**
     * 策略列表
     */
    @GetMapping("/policy")
    @ApiOperation("获取售货机策略列表")
    public List<Policy> findVmPolicy(VmPolicyListDto dto){
        log.info("获取售货机列表：{}",dto);
        List<Policy> list = vm.findVmPolicy(dto);
        return list;
    }

    /**
     * 售货机策略应用
     */
    @PutMapping("/vm/applyPolicy")
    @ApiOperation("售货机策略应用")
    public Boolean applyPolicy(@RequestBody VmPolicyListDto dto) throws Exception {
        log.info("售货机策略应用:{}",dto);
        vm.applyPolicy(dto);
        return true;
    }

    /**
     * 售货机取消策略
     */
    @PutMapping("/vm/cancelPolicy/{innerCode}/{policyId}")
    @ApiOperation("取消策略")
    public Boolean cancelPolicy(@PathVariable Integer innerCode){
        log.info("取消策略:{}",innerCode);
        vm.canncelPolicy(innerCode);
        return true;
    }

}
